package com.obggtc.picture.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.obggtc.picture.entity.User;
import com.obggtc.picture.mapper.UserMapper;
import com.obggtc.picture.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 用户服务实现类
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public User findByUsername(String username) {

        
     //  如果要从数据库查询，取消注释下面的代码
         QueryWrapper<User> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("username", username);
         return userMapper.selectOne(queryWrapper);

    }

    @Override
    public boolean login(String username, String password) {
        User user = findByUsername(username);
        if (user == null) {
            return false;
        }
        
        // 检查用户状态
        if (user.getStatus() != null && user.getStatus() == 0) {
            return false;
        }
        
        // 验证密码
        return passwordEncoder.matches(password, user.getPassword());
    }
} 